package name.huzhenbo.java.patterns.nullobject;

class StrongerString {
    private String value;

    private StrongerString(String value) {
        this.value = value;
    }

    public static StrongerString fetchStronger(String value) {
        if (value == null) {
            return NULL;
        }
        return new StrongerString(value);
    }

    public boolean containsNumeric() {
        for (char c : value.toCharArray()) {
            if (c >= '0' && c <= '9') {
                return true;
            }
        }
        return false;
    }

    private static final StrongerString NULL = new StrongerString(null) {

        @Override
        public boolean containsNumeric() {
            return false;
        }
    };
}
